<?php
require 'init.php';

if ( $contact ) {
    $edit_type = 'edit';
} else {
    $edit_type = 'new';
}

switch ( $action ) {
    case 'create':
        $_SESSION[ 'modified' ] = $d->create_contact( $_REQUEST[ 'fname' ], $_REQUEST[ 'lname' ], $_REQUEST[ 'email' ], $_REQUEST[ 'phone' ] );
        header( 'Location: index.php' );
        break;

    case 'save':
        $_SESSION[ 'modified' ] = $d->update_contact( $id, $_REQUEST[ 'fname' ], $_REQUEST[ 'lname' ], $_REQUEST[ 'email' ], $_REQUEST[ 'phone' ] );
        header( 'Location: index.php' );
        break;

    case 'cancel':
        header( 'Location: index.php' );
        break;

    case 'delete':
        $_SESSION[ 'modified' ] = $d->delete_contact( $id );
        header( 'Location: index.php' );
        break;
}

include 'templates/header.template.php';
include 'templates/edit.template.php';
include 'templates/footer.template.php';



?>
